"use strict";
cc._RF.push(module, 'f6e09THQkxH1KyoMWm8r0ay', 'PromoNode');
// scripts/PromoNode.js

"use strict";

var e = require;
var t = module;
var n = exports;
Object.defineProperty(n, "__esModule", {
  value: !0
});

var o = e("AniTool"),
    i = e("GIFSprite"),
    a = cc._decorator,
    r = a.ccclass,
    s = a.property,
    c = function (e) {
  __extends(t, e);

  function t() {
    var t = null !== e && e.apply(this, arguments) || this;
    t.pNode = null;
    t.image = null;
    t.nameLabel = null;
    t.redDot = null;
    t.freshTime = 5;
    t.aniType = o.AniType.无动画;
    t.mDatas = null;
    t.curData = null;
    t.pIndex = 0;
    return t;
  }

  t.prototype.onLoad = function () {
    SDK.Base.Event.on("getData", this.initData, this);
    this.initData();
  };

  t.prototype.onDestroy = function () {
    SDK.Base.Event.off("getData", this.initData, this);
  };

  t.prototype.initData = function () {
    if (SDK.Mgr.Inst.hasPromoData && (SDK.Mgr.Inst.curChannel != SDK.Define.Channel.oppo || SDK.Mgr.Inst.isAdOpen)) {
      this.node.active = !0;
      this.mDatas = Config.Base.promoData;
      this.setData();
    } else this.node.active = !1;
  };

  t.prototype.setData = function () {
    if (0 != this.mDatas.content.length) {
      this.pIndex = Math.floor(Math.random() * this.mDatas.content.length);
      this.pIndex >= this.mDatas.content.length && (this.pIndex = 0);
      this.curData = this.mDatas.content[this.pIndex];
      this.showData();
      this.unschedule(this.changePromo);
      this.schedule(this.changePromo, this.freshTime);
    }
  };

  t.prototype.showData = function () {
    if (SDK.Util.Helper.isGif(this.curData.imageUrl)) {
      (e = this.image.getComponent(i["default"])) || (e = this.image.addComponent(i["default"]));
      e.path = this.curData.imageUrl;
    } else {
      var e;
      (e = this.image.getComponent(i["default"])) && e.clear();
      SDK.Util.Helper.loadImage(this.image, this.curData.imageUrl);
    }

    this.nameLabel.string = this.curData.name;
    this.pNode.active = !0;
    this.redDot.active = !1;
    this.pNode.stopAllActions();
    SDK.Mgr.Inst.event("PromoShow_" + this.curData.key);

    if (this.aniType == o.AniType.扭动) {
      var t = cc.repeatForever(cc.sequence(cc.rotateTo(.15, -10).easing(cc.easeSineOut()), cc.rotateTo(.15, 10).easing(cc.easeSineOut()), cc.rotateTo(.15, -10).easing(cc.easeBackOut()), cc.rotateTo(.15, 10).easing(cc.easeSineOut()), cc.rotateTo(.15, -10).easing(cc.easeSineOut()), cc.rotateTo(.15, 0).easing(cc.easeSineOut()), cc.delayTime(2)));
      this.pNode.runAction(t);
    } else if (this.aniType == o.AniType.缩放) {
      t = cc.repeatForever(cc.sequence(cc.scaleTo(.15, 1.1).easing(cc.easeSineOut()), cc.scaleTo(.15, 1).easing(cc.easeSineOut()), cc.scaleTo(.15, 1.1).easing(cc.easeSineOut()), cc.scaleTo(.15, 1).easing(cc.easeSineOut()), cc.delayTime(2)));
      this.pNode.runAction(t);
    } else this.aniType == o.AniType.红点 && (this.redDot.active = !0);
  };

  t.prototype.changePromo = function () {
    if (0 != this.mDatas.content.length) {
      this.pIndex++;
      this.pIndex >= this.mDatas.content.length && (this.pIndex = 0);
      this.curData = this.mDatas.content[this.pIndex];
      this.showData();
    }
  };

  t.prototype.click = function () {
    var e = this;
    SDK.Mgr.Inst.event("PromoClick_" + this.curData.key);
    SDK.Mgr.Inst.promo(this.curData, function (t) {
      if (t) {
        e.unschedule(e.changePromo);
        e.schedule(e.changePromo, e.freshTime);
        e.changePromo();
      }
    });
  };

  __decorate([s(cc.Node)], t.prototype, "pNode", void 0);

  __decorate([s(cc.Sprite)], t.prototype, "image", void 0);

  __decorate([s(cc.Label)], t.prototype, "nameLabel", void 0);

  __decorate([s(cc.Node)], t.prototype, "redDot", void 0);

  __decorate([s({
    type: cc.Integer,
    displayName: "刷新时间"
  })], t.prototype, "freshTime", void 0);

  __decorate([s({
    type: cc.Enum(o.AniType),
    displayName: "动画类型"
  })], t.prototype, "aniType", void 0);

  return __decorate([r], t);
}(cc.Component);

n["default"] = c;

cc._RF.pop();